"use strict";

const os = require("os");

function formatBytes(bytes) {
	const units = ["B", "KB", "MB", "GB", "TB"];
	let value = bytes;
	let idx = 0;
	while (value >= 1024 && idx < units.length - 1) {
		value /= 1024;
		idx++;
	}
	return `${value.toFixed(2)} ${units[idx]}`;
}

console.log("=== System & Process Information ===");
console.log("CPU Arch:", process.arch);
console.log("OS Platform:", process.platform);
console.log("OS Release:", os.release());
console.log("Process ID:", process.pid);
console.log("Node Exec Path:", process.execPath);

const mu = process.memoryUsage();
console.log("\nProcess Memory Usage:");
console.log("- rss:", formatBytes(mu.rss));
console.log("- heapTotal:", formatBytes(mu.heapTotal));
console.log("- heapUsed:", formatBytes(mu.heapUsed));
console.log("- external:", formatBytes(mu.external));
if (typeof mu.arrayBuffers === "number") {
	console.log("- arrayBuffers:", formatBytes(mu.arrayBuffers));
}

console.log("\nSystem Memory:");
console.log("- total:", formatBytes(os.totalmem()));
console.log("- free:", formatBytes(os.freemem()));


